<template>
	
	<view class="content">
		
		<view class="form-k">
			<u-form :model="form" ref="uForm">
					<u-form-item label="身份证号" label-width="150" prop="idCardNo"><u-input v-model="form.idCardNo" /></u-form-item>
					<u-form-item label="身份证正面" label-width="160" prop="idCardFront">
						<u-upload :action="action" width="150" height ="150" upload-text='正面'
						 :max-count="1" :form-data="formdata" :file-list="fileListidCardFront" :show-progress="false"
						 @on-success="onsuccessfront"
						 @on-remove="onremovefront"
						></u-upload></u-form-item>
					<u-form-item label="身份证反面" label-width="160" prop="idCardBack">
						<u-upload :action="action"  width="150" height ="150" upload-text='反面' 
						 :max-count="1"  :form-data="formdata"  :file-list="fileListidCardBack"
						 @on-success="onsuccessback"
						 @on-remove="onremoveback"
						  :show-progress="false"
						></u-upload></u-form-item>
				</u-form>
				
				
			<u-button @click="submit" class="bt-">提交</u-button>
		</view>
		
		
		
		
	</view>
</template>

<script>
	import { BASE_URL_IMAHE } from "../../../../utils/https";
	import { saveFileUploads } from "@/api/upload";
	export default {
	  name: "infoindex",
	  data() {
		  return {
			form:{},  
			action: 'http://124.156.185.241/h5Shop/api/ln/saveFileUploads',
			rules: {
							idCardNo: [
								{
									required: true,
									message: '请输入身份证ID',
									trigger: ['blur', 'change']
								}
							],idCardFront: [
								{
									required: true,
									message: '请上传身份证正面',
									trigger: ['blur', 'change']
								}
							],idCardBack: [
								{
									required: true,
									message: '请上传身份证反面',
									trigger: ['blur', 'change']
								}
							]
						},
			formdata:{
				userId:""
			},
			fileListidCardFront: [
								
							],
			fileListidCardBack: [
								
							]

		  }
	  },
	  onLoad(options) {
		  console.log(JSON.parse(options.item))
			
		if(JSON.parse(options.item).idCardNo){
			this.form=JSON.parse(options.item)
			console.log(this.formdata)
			let imguri= BASE_URL_IMAHE;
			this.fileListidCardFront.push({
				url:imguri+ this.form.idCardFront
			})
			this.fileListidCardBack.push({
				url:imguri+ this.form.idCardBack
			})
			console.log(this.fileListidCardBack,this.fileListidCardFront)
			// fileListidCardFront[0].url=
			// fileListidCardBack[0].url=imguri+ this.formdata.idCardBack
		}
	    this.formdata.userId=uni.getStorageSync("userId")
	  },
	  onReady() {
		  
	  		this.$refs.uForm.setRules(this.rules);
	  	},
			
		methods:{
			submit() {
				var that=this
						this.$refs.uForm.validate(valid => {
							if (valid) {
								console.log('验证通过');
								console.log(this.form)
								let pages = getCurrentPages();//获取页面实例
												let nowPage = pages[pages.length - 1];//当前页面实例
												let prevPage = pages[pages.length - 2];//上一级页面实例
												console.log('qqq', pages, nowPage, prevPage)
												let carobj = this.form
												//在这个地方向上一个页面的实例的函数传递一个参数
												//Backcardaa函数是A页面中封装的函数
												prevPage.$vm.Backcardata(carobj)
												uni.navigateBack({
													delta: 1
												})
							} else {
								console.log('验证失败');
							}
						});
					},
			beforeupload(e){
				console.log("e",e)
			},
			 onsuccessfront(data, index,lists,name){
				console.log(data,index,lists,name)
				
				this.form.idCardFront=data.fileUrls[0]
				// let imguri= BASE_URL_IMAHE.indexOf("http://124.156.185.2414141")!=-1? BASE_URL_IMAHE :"htt124.156.185.241.241.241";
				// this.fileListidCardFront.push({
				// 	url:imguri+ this.formdata.idCardFront
				// })
				
				
			},
			onsuccessback(data, index,lists,name){
				console.log(data,index,lists,name)
				this.form.idCardBack=data.fileUrls[0]
				// let imguri= BASE_URL_IMAHE.indexOf("http://124.156.185.2414141")!=-1? BASE_URL_IMAHE :"htt124.156.185.241.241.241";
				// this.fileListidCardBack.push({
				// 	url:imguri+ this.formdata.idCardFront
				// })
				
			},
			onremovefront(index, lists, name){
				console.log(index,lists,name)
				this.form.idCardFront=""
				// this.fileListidCardFront.splice(index,1)
			},
			onremoveback(index, lists, name){
				console.log(index,lists,name)
				this.form.idCardBack=""
				// this.fileListidCardBack.splice(index,1)
			},
		}
	}
	  
</script>

<style scoped>
	page{
		/* padding-top: 2rpx; */
		padding-top: 20rpx;
	}
	.content{
		width: 705rpx;
		margin: 0 auto;
		height: 100%;
		background: #FFFFFF;
		border-radius: 10rpx 10rpx 10rpx 10rpx;
		padding: 20px ;
		
	}
		
	.form-k{
		width: 100%;
		padding: 24rpx;
		box-sizing: border-box;
	}
</style>